<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>demo</title>
    <script type="text/javascript" src="../vue.js"></script>
</head>

<body>
    <div id="app">
        <button @click="addPersonBefore">在前边添加一个人</button>
      <button @click="addPersonAfter">在后边添加一个人</button>

    </div>
</body>
<script type="text/javascript">
    Vue.config.productionTip = false
    const vm = new Vue({
        el: "#app",
        data() {
            return {
            persons: [
              { id: "001", name: "laowang", age: 19 },
              { id: "002", name: "xiaowang", age: 29 },
              { id: "003", name: "zhongwang", age: 9 },
            ],
          };
        },
        methods: {
          addPersonBefore() {
            // 对象点方法添加属性
            this.persons = [
              { id: Date.now(), name: "dawang", age: 22 },
              ...this.persons,
            ];
          },
          addPersonAfter() {
            this.persons = [
              ...this.persons,
              { id: Date.now(), name: "wangzhongwang", age: 32 },
            ];
          },
        },
    })
</script>

</html>